package com.basic.business.store.controller;


import java.util.List;
import java.io.IOException;
import java.util.Map;

import com.basic.business.mat.domain.TMatMgmt;
import com.basic.business.store.vo.StoreLeaderRespVo;
import com.basic.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.annotation.Resource;
import com.basic.common.annotation.FileExport;
import com.basic.common.utils.easyExcel.EasyExcelUtils;
import org.springframework.web.bind.annotation.*;
import com.basic.common.annotation.Log;
import com.basic.common.core.controller.BaseController;
import com.basic.common.core.domain.AjaxResult;
import com.basic.common.enums.BusinessType;
import com.basic.business.store.domain.TStoreMgmt;
import com.basic.business.store.service.ITStoreMgmtService;
import com.basic.common.core.page.TableDataInfo;

/**
 * 店铺管理Controller
 *
 * @author zhaoxy_jn@163.com
 */
@RestController
@RequestMapping("/business/storeMgmt")
public class TStoreMgmtController extends BaseController
{
    @Resource
    private ITStoreMgmtService tStoreMgmtService;

    /**
     * 查询店铺管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:storeMgmt:list')")
    @GetMapping("/list")
    public TableDataInfo list(TStoreMgmt tStoreMgmt)
    {
        startPage();
        List<TStoreMgmt> list = tStoreMgmtService.getList(tStoreMgmt);
        return getDataTable(list);
    }

    /**
     * 导出店铺管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:storeMgmt:export')")
    @Log(title = "店铺管理", businessType = BusinessType.EXPORT)
    @FileExport(fileName = "店铺管理.xlsx")
    @PostMapping("/export")
    public String export(TStoreMgmt tStoreMgmt) throws IOException
    {
        List<TStoreMgmt> list = tStoreMgmtService.getList(tStoreMgmt);
        return EasyExcelUtils.excelExport(TStoreMgmt.class,"店铺管理数据", list);
    }

    /**
     * 获取店铺管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:storeMgmt:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tStoreMgmtService.get(id));
    }

    /**
     * 新增店铺管理
     */
    @PreAuthorize("@ss.hasPermi('business:storeMgmt:add')")
    @Log(title = "店铺管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TStoreMgmt tStoreMgmt)
    {
        return toAjax(tStoreMgmtService.insert(tStoreMgmt));
    }

    /**
     * 修改店铺管理
     */
    @PreAuthorize("@ss.hasPermi('business:storeMgmt:edit')")
    @Log(title = "店铺管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TStoreMgmt tStoreMgmt)
    {
        return toAjax(tStoreMgmtService.update(tStoreMgmt));
    }

    /**
     * 删除店铺管理
     */
    @PreAuthorize("@ss.hasPermi('business:storeMgmt:remove')")
    @Log(title = "店铺管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tStoreMgmtService.deleteByIds(ids));
    }

    /**
     * 获取负责的店铺列表
     * @return
     */
    @GetMapping("/getStoreList")
    public AjaxResult getStoreList(){
        Long userId = SecurityUtils.getUserId();
        List<Map<String, Object>> list = tStoreMgmtService.getStoreIdListByUserId(userId);
        return success(list);
    }

    /**
     * 获取店铺状态正常的列表
     */
    @GetMapping("/getNormalStoreMgmtList")
    public AjaxResult getNormalStoreMgmtList(){
        List<TStoreMgmt> list = tStoreMgmtService.getNormalStoreMgmtList();
        return success(list);
    }

    /**
     * 状态变更
     */
    @PreAuthorize("@ss.hasPermi('business:storeMgmt:changeStatus')")
    @Log(title = "店铺管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestParam("ids") String[] ids, @RequestParam("status") String status)
    {
        return toAjax(tStoreMgmtService.updateStatusByIds(ids, status));
    }

    /**
     * 刷新缓存
     */
    @PreAuthorize("@ss.hasPermi('business:storeMgmt:refreshCache')")
    @Log(title = "店铺管理", businessType = BusinessType.CLEAN)
    @DeleteMapping("/refreshCache")
    public AjaxResult refreshCache()
    {
        tStoreMgmtService.resetStoreCache();
        return success();
    }

    /**
     * 字段重复判断
     */
    @GetMapping("/getDoesItExist")
    public AjaxResult getDoesItExist(TStoreMgmt tStoreMgmt)
    {
        List<TStoreMgmt> list = tStoreMgmtService.getDoesItExist(tStoreMgmt);
        return success(list);
    }

    /**
     * 获取店铺负责人列表
     */
    @GetMapping("/getStoreLeaderList")
    public AjaxResult getStoreLeaderList()
    {
        List<StoreLeaderRespVo> list = tStoreMgmtService.getStoreLeaderList();
        return success(list);
    }

}
